﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public partial class SalesOrder : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            CTIDLabel.Text = Session["CT_ID"].ToString();   //Set cart ID label to session ID
        TodayDate.Text = DateTime.Now.ToString();   //Displays today's date
    }

    double TotalAmount = 0.00;

    protected double Get_Amount(object price, object quantity)
    {
        double amount = 0;
        amount = Convert.ToDouble(price.ToString()) * Convert.ToDouble(quantity.ToString());
        TotalAmount += amount;
        return amount;
    }

    protected double Get_Shipping()
    {
        double shipping = TotalAmount * .10;
        TotalAmount += shipping;
        return shipping;
    }

    protected double Get_Order_Total()
    {
        return TotalAmount;
    }


     protected void Page_Unload(object sender, EventArgs e)  //Will delete items from the shopping cart once all events are finished
    {
        OleDbCommand DBCommand = new OleDbCommand();
        string SQLstring;

        OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Server.MapPath("App_Data\\Database1.accdb"));
        DBConnection.Open();

        SQLstring = "DELETE FROM CART " + "WHERE CT_ID= " + Session["CT_ID"];
        DBCommand = new OleDbCommand (SQLstring, DBConnection);
        DBCommand.ExecuteNonQuery();
        DBConnection.Close();

        //Assign a new cart ID in case they want to keep shopping
        Random random = new Random();
        int test;
        test = random.Next(0, 9999999);
        Session["CT_ID"] = test;
    }
}